package com.imcrl.net.loader
{
	import com.clayServer.net.loader.URLLoaderQueue;
	
	import flash.display.Loader;
	import flash.events.Event;
	import flash.system.LoaderContext;
	
	public class LoaderQueue extends URLLoaderQueue
	{
		private var loader:Loader;
		private var content:LoaderContext;
		public function LoaderQueue(content:LoaderContext)
		{
			super();
			
			loader=new Loader();
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE,activeObjectHandle);
		}
		
		override protected function completeHandler(event:Event):void{
			if(event.type==Event.COMPLETE){
				loader.loadBytes(urlLoader.data,content);
				return;
			}
			
			if(_currentItem.callBack !=null){
				_currentItem.callBack(event);
			}
			this.dispatchEvent(new Event(ITEM_COMPLETE));
			
			loadNext();
		}
		
		private function activeObjectHandle(event:Event):void{
			if(event==Event.COMPLETE){
				_currentItem.data=loader.content;
			}
			if(_currentItem.callBack !=null){
				_currentItem.callBack(event);
			}
			this.dispatchEvent(new Event(ITEM_COMPLETE));
			loadNext();
		}
	}
}